<?php

/*

  Action	$5

  You may reveal a Treasure card from your hand. Gain a copy of it.
  When you buy this, trash all Treasures you have in play.

 */

class Mint extends Card implements iAction, iKingdom, iProsperity {

    public function __construct() {
        parent::__construct("Mint", 5);
        $this->undoPlay = false;
        $this->undoBuy = true;
    }

    public function getDescription() {
        return array(
            "You may reveal a Treasure card from your hand. Gain a copy of it.",
            "When you buy this, trash all Treasures you have in play.");
    }

    public function play(Game $game, $isRealCard) {
        $playHand = $game->getPlayHand();
        $treasures = array();
        foreach ($playHand as $card) {
            if ($card instanceof iTreasure) {
                $treasures[] = $card;
            }
        }


        if (sizeof($treasures) > 0) {

            $treasures = getUniqueCards($treasures);
            if (sizeof($treasures) > 1) {
                $output = MySocket::GetUserReply($game, Input_ChooseOne, $treasures, 1, 1, null, "Choose card to mint");
                $card_name = $output[0];
            } else {
                $card_name = $treasures[0];
            }
            $card = $game->moveCardFromPileToPile($card_name, BoardCards, DiscardPile);
            ScreenDisplay::addScreenMessage($game, true, "reveal ".  nicePrint($card_name)." and gain " .  nicePrint($card), "reveals ".  nicePrint($card_name)." and gains " .  nicePrint($card));
        } else {
            ScreenDisplay::addScreenMessage($game, true, "gain nothing", "gains nothing");
        }
        $game->cardActionFinished();
        return true;
    }

    public function buy(Game $game) {
        $playArea = $game->getPlayArea();
        $treasures = array();
        foreach ($playArea as $card) {
            if ($card instanceof iTreasure) {
                $treasures[] = $card;
            }
        }
        ScreenDisplay::addScreenMessage($game, true, "trash " . nicePrint($treasures), "trashes " . ScreenDisplay::$LMSG);
        foreach ($treasures as $card) {
            $game->moveCardFromPileToPile($card, PlayArea, Trash);
        }
    }

}

?>